	//这里缓存下东西
	 var localCacheICert=null;
	 var localcertAarray=null;
	 var localdeviceSetObject=null;
	 var winWidth=0;
     var winHeight=0;

	function isHidden(oDiv){
		
      var vDiv = document.getElementById(oDiv);
      vDiv.style.display = (vDiv.style.display == 'none')?'block':'none';
    }
    function loadHtml()
    {
		//  var vDiv = document.getElementById("client_div");
	//	vDiv.style.height=winHeight+ "px";;
		
		
		SetConfig.value=NetcaPKI.getConfig();
        FilterCertCondition.value=NetcaPKI.getFilterCertCondition();
        comversioninfo.value=NetcaPKI.getVersion();
		EnvelopedDataSetEncAlgo.value=NetcaPKI.envelopedDataGetEncAlgo();
		SignedDataSetIncludeCertOption.value=NetcaPKI.signedDataGetIncludeCertOption();
		SetSelectCertPolicy.value=NetcaPKI.getSelectCertPolicy();
		SetPwdCacheOption.value=NetcaPKI.getPwdCacheOption()?0:1;
		//NetcaPKI.setSignAlgo("RSA",NetcaPKI.SHA1WITHRSA);
    }
	
	function  CertInvalid(cert)
	{
		if(cert==null) return;
		
		certInvalid1.checked=false;
		certInvalid2.checked=false;
		if(cert.match("InValidity='True'"))
		{
			certInvalid2.checked=true;
		}
		else
		{
			
			certInvalid1.checked=true;
		

		}
	}
	
	function  CertPublicKeyType(cert)
	{
		certPublicKeyType1.checked=false;
		certPublicKeyType2.checked=false;
		certPublicKeyType3.checked=false;
		if(cert.publicKeyType==1)
		{
			certPublicKeyType1.checked=true;
		}
		else if(cert.publicKeyType==2)
		{
			
			certPublicKeyType2.checked=true;
		

		}
		else
		{
			certPublicKeyType3.checked=true;
		}
	}
	function AutoShowtestCertficateBasePropety(cert)
	{
		if(cert==null) return;
		var showString="";
			showString+="序列号:	";showString+=cert.serialNumber;showString+="\n";
			showString+="公钥算法:	";showString+=cert.publicKeyAlgorithm;showString+="\n";
			showString+="公钥长度:	";showString+=cert.publicKeyBits;showString+="\n";
			showString+="KeyUsage:	";showString+=cert.keyUsage;showString+="\n";
			showString+="有效开始期限:	";showString+=cert.validFromDate;showString+="\n";
			showString+="有效截止期限:	";showString+=cert.validToDate;showString+="\n";
			showString+="颁发者:	";showString+=cert.issuer;showString+="\n";
			showString+="颁发者C:	";showString+=cert.issuerC;showString+="\n";
			showString+="颁发者ST:	";showString+=cert.issuerST;showString+="\n";
			showString+="颁发者L:	";showString+=cert.issuerL;showString+="\n";
			showString+="颁发者O:	";showString+=cert.issuerO;showString+="\n";
			showString+="颁发者OU:	";showString+=cert.issuerOU;showString+="\n";
			showString+="颁发者CN:	";showString+=cert.issuerCN;showString+="\n";
			showString+="主体名:	";showString+=cert.subject;showString+="\n";
			showString+="主体名C:	";showString+=cert.subjectC;showString+="\n";
		    showString+="主体名ST:	";showString+=cert.subjectST;showString+="\n";
			showString+="主体名L:	";showString+=cert.subjectL;showString+="\n";
		    showString+="主体名O:	";showString+=cert.subjectO;showString+="\n";
			showString+="主体名OU:	";showString+=cert.subjectOU;showString+="\n";
		    showString+="主体名CN:	";showString+=cert.subjectCN;showString+="\n";
			showString+="主体名Email:	";showString+=cert.subjectEmail;showString+="\n";
			showString+="PublicKeyType:	";showString+=(cert.publicKeyType==1)?("RSA"):(cert.publicKeyType==2)?"SM2":"ECC";showString+="\n";			
			showString+="CertClass:	";showString+=cert.certClass;showString+="\n";
			//alert(showString);  
		   Cert_Property.value=showString;
		   //判断有效性
		   CertInvalid(cert);
		   //证书公钥算法
		   CertPublicKeyType(cert);
   
		   //编码证书
		   JSTest_CertEncode();

		   //证书签名
		   if(cert.match("CertType='Signature'"))
		   {
			//JSTest_Sign();
			JSTest_SignedData_Sign();
		      
		   }
		   //证书加密
		   if(cert.match("CertType='Encrypt'"))
		   { 
			   JSTest_CertEncrypt();		   
		 	 JSTest_EnvelopedData_Encrypt();
		   }
	}
	
    function  JSTest_GetDeviceId()
	{
		try
		{
			 var arraryStr=NetcaPKI._baseObject.GetDeviceId();  
			 if(NetcaPKI.getLastError()!=NetcaPKI.OK)
             {
                alert(NetcaPKI.getLastErrorMsg());
				return;
             }
			 
			 var jsarray=(new VBArray(arraryStr)).toArray();
				if(jsarray.length==0)
				{
					alert("序列号个数为0");
					
				}
				else
				{
					
					var str="";
					for(var i=0;i<jsarray.length;++i)
					{
					    str+="{";
						str+=jsarray[i];
						str+="}";
					}
					
					GetDeviceId.value=str;
				}
		}
		catch(e)
		{
			alert(e.message+"  错误码 : "+e.number);
		}   
		
	}
	    function JSTest_VerifyDevicePwd()
      {
        try
		{
			 NetcaPKI._baseObject.VerifyDevicePwd(VerifyDeviceID.value,VerifyDevicePwd.value);    
             if(NetcaPKI.getLastError()!=NetcaPKI.OK)
             {
                alert(NetcaPKI.getLastErrorMsg());
				return;
             }
			
			 alert("验证成功");
		
		}
		catch(e)
		{
			alert(e.message+"  错误码 : "+e.number);
		}   
        
    }
	
	
	 
 
	function JSTest_getCertsFromStore()
	{
		try
		{
			localcertAarray= NetcaPKI.getCertsFromStore();    
			if(NetcaPKI.getLastError()!=NetcaPKI.OK)
            {
                alert(NetcaPKI.getLastErrorMsg());
				return;
            }
			if(localcertAarray==null)
			{
				alert("找不到证书");
				return;
			}
			var showString="";
			for(var i=0;i<localcertAarray.length;++i)
			{
				showString+=localcertAarray[i].subjectCN;
				showString+="\n";
			}
			
			
			alert(showString);
			 
		}
		catch(e)
		{
			alert(e.message+"  错误码 : "+e.number);
		}  
		
	}
	
	
		
	function JSTest_getCertsFromDevice()
	{
		try
		{
			localcertAarray= NetcaPKI.getCertsFromDevice();    
			if(NetcaPKI.getLastError()!=NetcaPKI.OK)
            {
                alert(NetcaPKI.getLastErrorMsg());
				return;
            }
			
			if(localcertAarray==null)
			{
				alert("找不到证书");
				return;
			}
			
			
			var showString="";
			var certArray = new Array();
			for(var i=0;i<localcertAarray.length;++i)
			{
				showString+=localcertAarray[i].subjectCN;
				showString+="\n";
				certArray.push(localcertAarray[i]);
			}

         
			//test getCerts
			var CertificatesArray=NetcaPKI.getCerts(certArray);
			alert(showString);
			 
		//	localCacheICert= NetcaPKI.getUserCert(parseInt(GetUserCertType.value)/*,GetUserCertCondition.value*/);    
		}
		catch(e)
		{
			alert(e.message+"  错误码 : "+e.number);
		}  
		
	}
	
	
	function JSTest_GetUserCertProperty()
	{
		try
		{
			if(localCacheICert==null)
			{
				alert("先选择证书");
				return;
			}
			
			testCertficateBasePropety(localCacheICert);
			
		}
		catch(e)
		{
			alert(e.message+"  错误码 : "+e.number);
		}  
		
	}
	 
	function JSTest_VerifyCertPwd()
	{
			if(localCacheICert==null)
			{
				alert("先选择证书");
				return;
			}
		    var  bOK=localCacheICert._cert.VerifyPwd(certPassword.value);
			if(bOK)
			{
				alert("验证密码成功");
			}
			else
			{
				alert("验证密码失败");
			}
	}
	function JSTest_CanGetCertPrivateKey()
	{
		  try
		{
			if(localCacheICert==null)
			{
				alert("先选择证书");
				return;
			}
			var  bOK=NetcaPKI._baseObject.CanGetCertPrivateKey(localCacheICert._cert,certPWD.value);
			
			if(bOK)
			{
				alert("可以获取密钥");
			}
			else
			{
				alert("获取不到密钥");
			}
			 
		}
		catch(e)
		{
			alert(e.message+"  错误码 : "+e.number);
		}  
		
	}
	
	function JSTest_Sign()
	{
		  try
		{
			if(localCacheICert==null)
			{
				alert("先选择签名的证书");
				return;
			}
 
			var signVar= NetcaPKI.sign(localCacheICert,SignTBS.value);    
			if(NetcaPKI.getLastError()!=NetcaPKI.OK)
            {
                alert(NetcaPKI.getLastErrorMsg());
				return;
            }
			var base64String= NetcaPKI.base64Encode(signVar);
		    SignPVAL.value=base64String;
		}
		catch(e)
		{
			alert(e.message+"  错误码 : "+e.number);
		}  
		
	}
	function JSTest_Verify()
	{
		  try
		{
			if(localCacheICert==null)
			{
				alert("先选择签名的证书");
				return;
			}
			var  signature=NetcaPKI.base64Decode(Signature.value);
			var  signVar= NetcaPKI.verify(localCacheICert,VerifyTBS.value,signature);    
			if(NetcaPKI.getLastError()!=NetcaPKI.OK)
            {
                alert(NetcaPKI.getLastErrorMsg());
				return;
            }
			if(signVar)
			{
				alert("验证签名成功!");
			}
			else
			{
			  alert("验证签名失败!");
			}
		}
		catch(e)
		{
			alert(e.message+"  错误码 : "+e.number);
		}  
		
	}
		
	 